/*
 * @Description: 
 * @Author: wangqi
 * @Date: 2021-04-17 12:05:11
 * @LastEditTime: 2021-04-18 12:22:51
 */
class SyncWaterfallHook {
    constructor(args) {
        this.hooks = [];
    }

    tap(name, task) {
        this.hooks.push(task);
    }

    call(...res) {
        let [first, ...other] = this.hooks
        let ret = first(...res)
        other.reduce((prev, curr) => curr(prev), ret)
    }
}

let syncwaterfallhook = new SyncWaterfallHook(['name', 'age']);
syncwaterfallhook.tap('node', (name, age) => {
    console.log('node', name, age);
    return '来自外部'
});

syncwaterfallhook.tap('vue', (data) => {
    console.log('vue', data)
    return '来自node'
});

syncwaterfallhook.tap('react', (data) => {
    console.log('react', data)
    return '来自vue'
});

syncwaterfallhook.call('wq', 12);


